package com.jinwei.qunguanjia.web.user.controller;

import com.jinwei.qunguanjia.common.core.domain.Response;
import com.jinwei.qunguanjia.common.core.page.PageDataInfo;
import com.jinwei.qunguanjia.common.utils.PageDataUtil;
import com.jinwei.qunguanjia.common.utils.PageUtils;
import com.jinwei.qunguanjia.common.utils.SystemContextUtils;
import com.jinwei.qunguanjia.user.dto.BlacklistDTO;
import com.jinwei.qunguanjia.user.service.BlacklistService;
import com.jinwei.qunguanjia.web.user.vo.BlacklistVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 黑名单管理相关接口
 *
 * @author yuanzs
 */
@RestController
@RequestMapping("/blacklist")
public class BlacklistController {

    @Resource
    private BlacklistService blacklistService;

    /**
     * 黑名单列表
     */
    @GetMapping("/listPage")
    public PageDataInfo<BlacklistVO> list() {
        BlacklistDTO blacklistDTO = new BlacklistDTO();
        blacklistDTO.setUserId(SystemContextUtils.getUserId());
        PageUtils.startPage();
        PageDataUtil<BlacklistDTO, BlacklistVO> pageDataUtil = new PageDataUtil<>();
        return pageDataUtil.transform(blacklistService.listPage(blacklistDTO), BlacklistVO.class);
    }

    /**
     * 拉黑接口
     */
    @PostMapping("/save")
    public Response save(BlacklistVO blacklistVO) {
        String userId = SystemContextUtils.getUserId();
        BlacklistDTO blacklistDTO = BlacklistDTO.builder()
                .userId(userId)
                .blacklistUserId(blacklistVO.getBlacklistUserId())
                .build();
        blacklistService.save(blacklistDTO);
        return Response.success();
    }

    /**
     * 解除拉黑接口
     */
    @PostMapping("/remove")
    public Response remove(BlacklistVO blacklistVO) {
        blacklistService.remove(blacklistVO.getBlacklistId());
        return Response.success();
    }
    
}
